package dearchenpush.good.com.qianfanlive.modules.live.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import dearchenpush.good.com.qianfanlive.R;
import dearchenpush.good.com.qianfanlive.modules.live.bean.LiveInBean;

/**
 * Created by Administrator on 2016/9/28.
 */
public class LiveInAdapter extends RecyclerView.Adapter<LiveInAdapter.StageViewHolder>  {
    private Context context;
    private List<LiveInBean.MessageBean.AnchorsBean> data;
    private StageViewHolder holder;
    private View.OnClickListener listener;


    public LiveInAdapter(Context context, List<LiveInBean.MessageBean.AnchorsBean> data) {
        Log.e("dddd", "LiveInAdapter:");
        this.context = context;
        this.data = data;
        //
    }
    public void setClickListener(View.OnClickListener listener){
        this.listener = listener;
    }

    @Override
    public StageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_live_in_adapteritem, parent, false);
        holder = new StageViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(StageViewHolder holder, int position) {

        LiveInBean.MessageBean.AnchorsBean anchorsBean = data.get(position);
        int size=position%4;

        holder.textVieworsFocus.setText(anchorsBean.getFocus() + "");
        holder.textViewName.setText(anchorsBean.getName());
        holder.imageViewIcon.setTag(position);

        if (listener != null) {
            holder.imageViewIcon.setOnClickListener(listener);
        }



        if (size == 0 || size == 2) {

            Picasso.with(context).load(anchorsBean.getPic74()).into(holder.imageViewIcon);

        } else if (size==1||size==3){
            Picasso.with(context).load(anchorsBean.getPic51()).into(holder.imageViewIcon);

        }



    }

    @Override
    public int getItemCount() {
      //  Log.e("--------->>>", "getItemCount: "+data.size());
        return data!=null?data.size():0;
    }




    public static class StageViewHolder extends RecyclerView.ViewHolder {
        private TextView textViewName;
        private TextView textVieworsFocus;
        private  ImageView imageViewmark;
        private ImageView imageViewIcon;
        private ImageView imageViewOnline;
        public StageViewHolder(View itemView) {
            super(itemView);
            textViewName = (TextView) itemView.findViewById(R.id.fragment_live_in_item_name);
            textVieworsFocus = (TextView) itemView.findViewById(R.id.fragment_live_in_item_focus);
            // textVieworsFocus = (TextView) itemView.findViewById(R.id.fragment_live_in_item_focus);
            imageViewmark = (ImageView) itemView.findViewById(R.id.fragment_live_item_marklive);
            imageViewIcon = (ImageView) itemView.findViewById(R.id.fragment_live_item_imageview);
            imageViewOnline = (ImageView) itemView.findViewById(R.id.fragment_live_item_online);


        }
    }

}
